package com.bluefish.bltuan.module.shop;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import com.bluefish.bltuan.module.user.User;

@Entity
@Table(name = "Orders")
public class Order implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private static final int VERY_DISSATISFIED = 1; //很不满意
	
	private static final int DISSATISFIED = 2; //不满意
	
	private static final int COMMON = 3; //一般
	
	private static final int PLEASED = 4; //满意
	
	private static final int VERY_PLEASED = 5; //很满意
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer id;
	
	private String number; //订单编号
	
	private Date orderTime; //下单时间
	
	private int amount; //总价格

	//private boolean dealState;  //交易状态 true:完成 false:未完成
	
	private boolean pay;  //是否付款 true:完成 false:未完成
	
	private int please; //满意程度 1: 2: 3: 4: 5:
	
	private String assess; //评价
	
	private String action;  //操作名称
	
	//private int piece; //个数
	
	@OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
	private User user;
	
	@OneToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
	private TuanGou tuangou;

	@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	private Delivery delivery;
	
	public int getPiece() {
		return (int) (getAmount() / getTuangou().getCurrentPrice());
	}

	/*public void setPiece(int piece) {
		this.piece = piece;
	}*/

	public Delivery getDelivery() {
		return delivery;
	}

	public void setDelivery(Delivery delivery) {
		this.delivery = delivery;
	}

	public TuanGou getTuangou() {
		return tuangou;
	}

	public void setTuangou(TuanGou tuangou) {
		this.tuangou = tuangou;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}


	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getNumber() {
		return number;
	}

	public void setNumber(String number) {
		this.number = number;
	}

	public Date getOrderTime() {
		return orderTime;
	}

	public void setOrderTime(Date orderTime) {
		this.orderTime = orderTime;
	}

	public int getAmount() {
		return amount;
	}

	public void setAmount(int amount) {
		this.amount = amount;
	}


	public boolean isPay() {
		return pay;
	}

	public void setPay(boolean pay) {
		this.pay = pay;
	}

	public int getPlease() {
		return please;
	}

	public void setPlease(int please) {
		this.please = please;
	}

	public String getAssess() {
		return assess;
	}

	public void setAssess(String assess) {
		this.assess = assess;
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	public void oneStar(){
		setPlease(VERY_DISSATISFIED);
	}
	
	public void twoStar(){
		setPlease(DISSATISFIED);
	}
	
	public void threeStar(){
		setPlease(COMMON);
	}

	public void fourStar(){
		setPlease(PLEASED);
	}

	public void fiveStar(){
		setPlease(VERY_PLEASED);
	}
	
	public void score(int type){
		switch (type) {
		case 1:
			oneStar();
			break;
		case 2:
			twoStar();
			break;
		case 3:
			threeStar();
			break;
		case 4:
			fourStar();
			break;
		case 5:
			fiveStar();
			break;

		default:
			break;
		}
	}
	
	/**
	 * 支付成功
	 */
	public void pay(){
		this.setPay(true);
	}
	
	/**
	 * 支付失败
	 */
	public void unPay(){
		this.setPay(false);
	}
}
